package com.scott.java8concurrency.java5;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ExcutorDemo {

    public static void main(String[] args) {
        //执行器，线程池是他的一种实现
        //线程池 是线程的复用
        Executor executor = Executors.newFixedThreadPool(1);

        executor.execute(() ->  System.out.printf("[thread:%s] staring\n", Thread.currentThread().getName()));

        //线程执行器 在执行后，是不会自动停止的，需要在合适的时候，合理的关闭线程池
        if(executor instanceof ExecutorService){
            ExecutorService executorService = ExecutorService.class.cast(executor);
            executorService.shutdown();
        }
    }
}
